import React, { useState } from 'react';
import Experiments from './Experiments';
import ExperimentEdit from './ExperimentEdit';
import ExperimentView from './ExperimentView';
import JsonViewer from '../general/JsonViewer';
import { EXPERIMENT_VIEWS } from '../../constants';

interface ExperimentManagerProps {
  [key: string]: any;
}

/**
 * ExperimentManager Component
 * Main component for managing experiments
 * Coordinates between Experiments list, ExperimentEdit, and ExperimentView
 */
const ExperimentManager: React.FC<ExperimentManagerProps> = (props) => {
  const [editState, setEditState] = useState<boolean>(false);
  const [experimentName, setExperimentName] = useState<string | null>(null);
  const [trial, setTrial] = useState<string | null>(null);
  const [trialJSON, setTrialJSON] = useState<any>(null);
  const [view, setView] = useState<string>(EXPERIMENT_VIEWS.list);

  const viewHandler = (): React.ReactNode => {
    switch (view) {
      case EXPERIMENT_VIEWS.list:
        return (
          <Experiments
            setEditState={setEditState}
            setExperimentName={setExperimentName}
            setView={setView}
          />
        );
      case EXPERIMENT_VIEWS.viewExperiment:
        return (
          <ExperimentView
            name={experimentName || ''}
            setTrial={setTrial}
            setTrialJSON={setTrialJSON}
            setView={setView}
          />
        );
      case EXPERIMENT_VIEWS.edit:
        return (
          <ExperimentEdit
            editState={editState}
            name={experimentName}
            setView={setView}
          />
        );
      case EXPERIMENT_VIEWS.jsonViewer:
        return (
          <JsonViewer
            baseTitle={experimentName}
            json={trialJSON}
            title={trial}
            setView={setView}
          />
        );
      default:
        return (
          <Experiments
            setEditState={setEditState}
            setExperimentName={setExperimentName}
            setView={setView}
          />
        );
    }
  };

  return <>{viewHandler()}</>;
};

export default ExperimentManager;

